package auctions;
import java.util.*;

public abstract class AuctionHouse {
	
	protected int _numBidders;
	protected int _numAuctions;
	protected Vector<Integer> _paymentRule;
	protected Vector<Agent> _agents;
	protected Vector<Double> _reserves;
	protected Vector<BidderResults> _bresults;
	protected String _outputFile;
	protected Vector<AuctionType> _auctionTypes;
	protected Vector<Auction> _auctions;
	
	
	public AuctionHouse(String outputFile, Vector<Agent> agents, Vector<Integer> paymentRule, Vector<Double> reserves, Vector<AuctionType> at) {
		_outputFile = outputFile;
		//this.setAgents(agents);
        _numAuctions = at.size();
        this.setPaymentRules(paymentRule);
        this.setReserves(reserves);
        _auctionTypes = at;
        _auctions = new Vector<Auction>();
        for (int i = 0; i<_numAuctions; i++) {
        	switch (at.get(i)) {
        		case SEALEDBID:
        			_auctions.add(new SealedBidAuction(i, _outputFile, _numBidders, _reserves.get(i), _paymentRule.get(i)));
        			break;
        		case ASCENDING:
        			_auctions.add(new AscendingAuction(i, outputFile, _numBidders, _reserves.get(i), _paymentRule.get(i)));
        			break;
        	}
        	//_auctions.get(i).setAgents(agents);
        		
        }
	}
	
	public Vector<AuctionType> getAuctionTypes() {
		return _auctionTypes;
	}
	
	public void setPaymentRules(Vector<Integer> paymentRule){ 
	
		/**
		 * Takes a vector of payment rules  (one for each auction)
		 * If the Vector of rules is smaller than the number of auctions
		 * all remaining rules are set to the last rule in
		 * the vector.  To give all auctions the same rule  pass
		 * in a vector with one element equal to the desired payment rule
		 */
		_paymentRule = new Vector<Integer>();
		
		for (int i = 0; i<this._numAuctions; i++) {
			if (i < paymentRule.size()) {
				_paymentRule.add(paymentRule.get(i));
			} else {
				_paymentRule.add(paymentRule.lastElement());
			}
			
		}
	
	}
	
	public void setAgents(Vector<Agent> agents) {
		_agents = agents;
		_numBidders = agents.size();
        for (Auction a : _auctions) {
            a.setAgents(_agents);
        }
	}
	
	public void setReserves(Vector<Double> reservePrices) {
		/**
		 * Takes a vector of reserve prices (one for each auction)
		 * If the Vector of reserves is less than the number of auctions
		 * all remaining reserves are set to the last reserve price in
		 * the vector.  To give all auctions the same reserve price pass
		 * in a vector with one element equal to the desired reserve price
		 */
		_reserves = new Vector<Double>();
		
		for (int i = 0; i<this._numAuctions; i++) {
			if (i < reservePrices.size()) {
				_reserves.add(reservePrices.get(i));
			} else {
				_reserves.add(reservePrices.lastElement());
			}
			
		}
	}

    public Auction getAuction(int i){
        return _auctions.get(i);
    }
	public Vector<Double> getReserves() {
		return _reserves;
	}

    public int getNumAuctions() {
    	return _numAuctions;
    }
	
	public abstract Results getWinners();
	
	public abstract AuctionHouseType getType();
	
	
}
